import React, { PureComponent } from "react";

import Home from "./pages/home/index";

import {
  Floor,
  Util,
  FloorManager
} from "@marslibs/yfereact-freetemplate-common";

export default class JDReactIsvShopModule extends PureComponent {
  constructor(props) {
    super(props);
    // 调试预览时可暂时注释掉
    this.state = {
      data: Util.getSafeFloorData(this.props.data)
    };
    // 注册监听楼层刷新，调试预览时可暂时注释掉
    FloorManager.addFloorDataUpdateListener(this, props.id);
  }

  render() {
    //  【发布打包时】生成bundle时需要使用Floor包裹的形式，调试预览时可暂时注释掉
    //  this.props.id       楼层的id    必传
    //  this.props.data     楼层的数据  必传
    return (
      <Floor id={this.props.id} data={this.props.data}>
        <Home data={this.state.data}></Home>
      </Floor>
    );
  }
  /**
   * 监听楼层刷新后的回调方法
   *
   * @param {Object} data 智铺接口返回的楼层数据
   * @memberof Example
   */
  onFloorDataUpdate(data) {
    this.setState({
      data
    });
  }

  /**
   *  监听楼层滚动回调方法
   *
   * @param {number} firstRow
   * @param {number} lastRow
   * @param {boolean} visible
   * @param {number} firstShowRow
   * @param {number} offset
   * @memberof Example
   */
  onListScroll(firstRow, lastRow, visible, firstShowRow, offset) {
    console.log(
      `firstRow:${firstRow}-lastRow=${lastRow}-visible${visible}-firstShowRow${firstShowRow}-offset${offset}`
    );
  }

  /**
   * 监听页面显示隐藏的回调方法
   *
   * @param {string} pageId
   * @param {boolean} showStatus
   * @memberof Example
   */
  onPageShowStatusChange(pageId, showStatus) {
    console.log(`pageId=${pageId}-showStatus=${showStatus}`);
  }

  // 调试预览时可暂时注释掉
  addListener() {
    let { pageId, uid } = FloorManager.getFloorIdentiInfo(this, this.props.id);

    // 监听页面显示隐藏
    PageVisibleManager.addPageShowStatusListener(this, pageId);

    // 监听楼层滚动
    ListScrollManager.addScrollListener(this, pageId, uid);
  }
}
